<template>
  <div class="login">
       <image class="logo" src="/static/images/logo.png"/>
       <div class="sign">童e时代</div>
       <div style="width:622rpx;height:2rpx;background:#e9e9e9;margin:auto"></div>
       <div class="please">请确认一下授权信息</div>
       <div class="obtain">获取您的信息（头像，昵称等）</div>
       <button class="grant" open-type="getUserInfo"  @getuserinfo="getUserInfo">授权</button>
  </div>
</template>

<script>
export default {
  data () {
    return {
      value:''
    }
  },
   methods: {
      getUserInfo(){
        var that=this
        wx.login({
          success: res => {
            wx.getSetting({
              success(res) {
                console.log(res)
                if (res.authSetting['scope.userInfo']) {
                  wx.showToast({
                      title: '授权登录成功',
                      icon: 'success',
                      duration: 2000,
                      success:function () {
                        
                      }
                    })
                    wx.getUserInfo({
                        success: function(res) {
                          console.log(res,'33333')
                          if(res.errMsg=='getUserInfo:ok'){
                            wx.switchTab({
                              url:'/pages/index/main'
                            })
                          }
                        }
                      })
                  // wx.authorize({
                  //   scope: 'scope.userInfo',
                  //   success () {
                      
                  //   }
                  // })
                }else{
                   wx.showToast({
                      title: '授权登录失败',
                      icon: 'success',
                      duration: 2000,
                      success:function () {  
                      }
                    })
                  }
                }
              })
            }
        })
        
      }
   },
 onShareAppMessage: function(options) {
    console.log(options,'options')
		wx.getShareInfo({
        // 把票据带上
        shareTicket: options.shareTicket,
        success: function (res) {
          console.log(res)
            // 如果从小程序分享没有source，如果从别人分享的再二次分享带有source
            // 后续会讲_this.data.source的来源
            // let source = _this.data.source ? _this.data.source : '';
            // 上报给后台，把群信息带给后台，后台会去解密得到需要的信息
            // _this.upload_share_Result(res, '1', source)
        }
    })
	},
  created () {
    // let app = getApp()
   
  },
  onLoad(){
     wx.showShareMenu({
      withShareTicket: true
    })
    wx.getSystemInfo({
        success (res) {
          console.log(res.version,'微信版本号，低于7.0.0请更新')
         
        }
      })	
      // this.list.map((item,index)=>{
      //   this.list[index].heart_id=false
      // })
  },

}
</script>

<style  lang="less">
  html{
    background: #f5f5f5;
  }
  .login{
    width: 100%;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    .logo{
      width: 138rpx;
      height: 138rpx;
      margin: 100rpx 0rpx 20rpx 0rpx;
    }
    .sign{
      font-size:36rpx;
      color: #333;
      font-weight:400;
      margin: 0rpx 0rpx 54rpx 0rpx;
    }
    .please{
      color: #333;
      font-size: 32rpx;
      font-weight:400;
      margin-top: 66rpx;
    }
    .obtain{
      font-size:28rpx;
      color: #888;
      margin: 16rpx 0  88rpx 0;
    }
    .grant{
      width:632rpx;
      height:94rpx;
      background:rgba(26,173,25,1);
      opacity:1;
      border-radius:20rpx;
      line-height: 94rpx;
      text-align: center;
      font-size:36rpx;
      color: #fff;
      button{
        width:632rpx;
        height:94rpx;
        background:rgba(26,173,25,1);
      }
    }
  }
</style>
